package 蓝桥._2024.最大异或结点;

import java.util.Scanner;
// 1:无需package
// 2: 类名必须Main, 不可修改

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        //在此输入您的代码...
        int n = scan.nextInt();
        int[] x = new int[n];
        int[] f = new int[n];
        for (int i = 0; i < n; i++) {
            x[i] = scan.nextInt();
        }
        for (int i = 0; i < n; i++) {
            f[i] = scan.nextInt();
        }
        int max = 0;
        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                if(f[i] != j && f[j] != i){
                    max = Math.max(max, x[i] ^ x[j]);
                }
            }
        }
        System.out.println(max);
        scan.close();
    }
}